<#include "../../select.ftl" />
<#assign shmsConstant = statics["cn.hfatec.shms.constants.ShmsConstant"]/>
<!-- Modal -->
<div class="modal-dialog wide" style="width: 550px;">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">
            <#if ykManage??>
                <#if ykManage.id??>
                    编辑
                <#else>
                    新增
                </#if>
            </#if>
            </h4>
        </div>
        <div class="modal-body">
            <div id="errorMessage"><#include "../../message.ftl" /></div>
            <form class="form-horizontal" role="form" id="ykManageForm" method="post"
                  action="${absoluteContextPath}/members/ykManage/save">
            <#if ykManage??>
                <#if ykManage.id??>
                    <input type="hidden" name="id" value="${ykManage.id?c}"/>
                <#else>
                    <input type="hidden" name="id" value=""/>
                </#if>
            </#if>
                <div class="row">

                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">下单日期</label>

                        <div class="col-sm-6">
                            <input type="hidden" name="billId" value="${ykManage.billId!''}"/>
                            <input name="billTime" value="${(ykManage.billTime?string("yyyy-MM-dd"))!''}" type="text"
                                   class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">客户姓名</label>

                        <div class="col-sm-6">
                            <div class="input-group">
                                <input name="customerName" value="${ykManage.customerName!''}" type="text"
                                       class="form-control"
                                       readonly="true"/>
                                <input name="cardId" id="cardId2" value="${ykManage.cardId!''}"
                                       type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="dorefreshCustome(this);"><i
                                        class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">产品名称</label>

                        <div class="col-sm-6">
                            <div class="input-group">
                                <input name="productName" value="${ykManage.productName!''}" type="text"
                                       class="form-control"
                                       readonly="true"/>
                                <input name="vipId" id="vipId2" value="${ykManage.vipId!''}"
                                       type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="dorefreshcardtype(this);"><i
                                        class="fa fa-search"></i></span>
                            </div>


                        <#--<input name="vipId" value="${ykManage.vipId!''}" type="text" class="form-control"/>-->
                        </div>
                    </div>

                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">渠道类型</label>

                        <div class="col-sm-6">
                        <@select name="channelType" value="${ykManage.channelType!''}" list=channelTypeList class="form-control"/>

                    <#--<input name="vipType" value="${cardType.vipType!''}" type="text" class="form-control"/>-->

                        </div>
                    </div>


                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">开卡日期</label>

                        <div class="col-sm-6">
                            <input name="startDate" value="${(ykManage.startDate?string("yyyy-MM-dd"))!''}" type="text"
                                   class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">到期日期</label>

                        <div class="col-sm-6">
                            <input name="endDate" value="${(ykManage.endDate?string("yyyy-MM-dd"))!''}" type="text"
                                   class="form-control"/>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">引荐人</label>

                        <div class="col-sm-6">

                            <div class="input-group">
                            <#if userNameYj??>
                                <input name="userNameYj" value="${userNameYj}" type="text"
                                       class="form-control" readonly="true"/>
                            <#else>
                                <input name="userNameYj" value="${ykManage.userNameYj!''}" type="text"
                                       class="form-control" readonly="true"/>
                            </#if>
                                <input name="healthYj" value="${ykManage.healthYj!''}"
                                       type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="doSelctHealthYj(this);"><i
                                        class="fa fa-search"></i></span>
                            </div>

                        <#--<input name="healthYj" value="${ykManage.healthYj!''}" type="text" class="form-control"/>-->
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">促会人</label>

                        <div class="col-sm-6">
                            <div class="input-group">
                            <#if userName??>
                                <input name="userName" value="${userName}" type="text"
                                       class="form-control" readonly="true"/>
                            <#else>
                                <input name="userName" value="${ykManage.userName!''}" type="text"
                                       class="form-control" readonly="true"/>
                            </#if>
                                <input name="healthCh" value="${ykManage.healthCh!''}"
                                       type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="doSelctIllIndex(this);"><i
                                        class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">分管人</label>

                        <div class="col-sm-6">
                            <div class="input-group">
                                <input name="userNameFg" value="${ykManage.userNameFg!''}" type="text"
                                       class="form-control"
                                       readonly="true"/>
                                <input name="healthFg" id="healthFg2" value="${ykManage.healthFg!''}"
                                       type="hidden" class="form-control">
                                <span class="input-group-addon" onclick="doSelctReferralsUser(this);"><i
                                        class="fa fa-search"></i></span>
                            </div>
                        </div>
                    <#--<div class="col-sm-6">-->
                    <#--<input name="healthFg" value="${ykManage.healthFg!''}" type="text" class="form-control"/>-->
                    <#--</div>-->
                    </div>
                    <div class="form-group col-md-12">
                        <label class="col-sm-4 control-label">副会</label>

                        <div class="col-sm-6">
                            <input name="vipFh" value="${ykManage.vipFh!''}" type="text" class="form-control"/>
                        </div>
                    </div>

                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            <button type="button" class="btn btn-primary" onclick="save();">保存</button>
        </div>
    </div>
</div>
<script>
    $(function () {
        $("select[name=channelType]").change(function () {
            if ($("input[name='vipId']").val() != '' && $("input[id='cardId2']").val() != '') {
                if ($(this).val() == 3 && $("input[name='id']").val() == '') {
                    channelTypeOnclick($(this).val(), $("input[name='vipId']").val(), $("input[id='cardId2']").val(), $("input[name='id']").val());
                }
            }
            else {
                $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：" + "客户姓名或产品名称不能为空", type: "error"});
            }
        });

    });


    function save() {
        $("#" + "ykManageForm").ajaxSubmit({
            success: function (data) {
                data = JSON.parse(data);
                if (data.returnCode == 1) {
                    $('#myModal').modal("hide");
                    $.showMessage({parentId: "showMessage", message: "信息保存成功！", type: "success"});
                    refreshTable();
                } else {
                    $.showMessage({parentId: "errorMessage", message: "<strong>错误信息</strong>：" + data.returnMsg, type: "error"});
                }
            }
        });
    }

    $(function () {
        $("input[name=billTime]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});

        })

        $("input[name=startDate]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        })
        $("input[name=startDate]").blur(function () {
            if ($(this).val() != '') {
                blurOnclick($(this).val(), $("input[name='vipId']").val());
            }
        })
        $("input[name=endDate]").focus(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        })

        $("div[class='tooltip fade top in']").hide();
    });

    function channelTypeOnclick(channelType, vipId, cardId, id) {
        var data = {};
        var url = '${absoluteContextPath}/members/ykManage';
        if (channelType == 3 && id == '') {
            data.vipId = vipId;
            data.cardId = cardId;
            url = url + "/goFind";
        }
        var sdf = "yyyy-MM-dd"
        $.ajax({
            url: url,
            type: 'post',
            data: data,
            success: function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
//                    console.info(data);
                    if (data.content.startDate != null) {
                        var date = new Date(data.content.startDate);
                        var startTime = date.format(sdf);
                        $("#ykManageForm input[name='startDate']").val(startTime);
                    }
                    if (data.content.endDate != null) {
                        var date2 = new Date(data.content.endDate);
                        var endTime = date2.format(sdf);
                        $("#ykManageForm input[name='endDate']").val(endTime);
                    }

                } else {
                    $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                }
            }
        });
    }
    function blurOnclick(startDate, vipId) {
        var data = {};
        var url = '${absoluteContextPath}/members/ykManage';
        if (startDate != '' && vipId != '') {
            data.startDate = startDate;
            data.vipId = vipId;
            url = url + "/goBlur";
        }
        var sdf = "yyyy-MM-dd"
        $.ajax({
            url: url,
            type: 'post',
            data: data,
            success: function (data) {
                var data = JSON.parse(data);
                if (data.returnCode == 1) {
//                    console.info(data);

                    if (data.content.endDate != null) {
                        var date2 = new Date(data.content.endDate);
                        var endTime = date2.format(sdf);
                        $("#ykManageForm input[name='endDate']").val(endTime);
                    }

                } else {
                    $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                }
            }
        });
    }

</script>